﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    public Transform target;//目标
    public float speed = 10f;//移动速度
    private void Update()
    {
        if (target == null)
        {
            transform.Translate(Vector3.forward * Time.deltaTime * speed);
            if (transform.position.y < -1)
            {
                Destroy(this.gameObject);
            }
            return;
        }

        transform.LookAt(target);
        transform.position = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
        //判断是否到达敌人的位置
        if (transform.position == target.position)
        {
            target.GetComponent<Monter>().GetHurt(1);
            Destroy(this.gameObject);
        }
    }
}